<?php



require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(DEDEINC.'/enums.func.php');
require_once(dirname(__FILE__)."/../include/province_short.inc.php");
if(empty($dopost)) $dopost = '';


// 搜索部分
if(empty($keyword)||$keyword=='输入学校名称') $keyword = '';
$search = '1';
if ($search_area!='0'&&!empty($search_area)) {
	$search .= " AND area = $search_area";
}
if ($search_scoretype!='0'&&!empty($search_scoretype)) {
	$search .= " AND scoreType = $search_scoretype";
}
if ($search_feerange!='0'&&!empty($search_feerange)) {
	$search .= " AND feeRange = $search_feerange";
}
if ($search_projecttype!='0'&&!empty($search_projecttype)) {
	$search .= " AND FIND_IN_SET($search_projecttype,projectType)";
}
if ($search_level!='0'&&!empty($search_level)) {
	$search .= " AND FIND_IN_SET($search_level,level)";
}
$order='';
if ($orderby!='0'||!empty($orderby)) {
	$order="order by lowestFee ".$orderby;
}


// 通过cookie获取最近浏览的院校的id
$history_id = rtrim($history_id,',');
$history_ids = explode(',', $history_id);
$history_ids_str = join(',',$history_ids);
// 获取最佳浏览的院校的数组
$sql = "SELECT * FROM `#@__collegeinfo` WHERE  collegeId IN ($history_ids_str)";
$dsql->SetQuery($sql);
$dsql->Execute();
$history_college = array();
while($row = $dsql->GetArray()){
    $history_college[] = $row;
}

// 推荐院校的数组
$recommend_college = CollegeRecommend($history_ids);

// 联系我们传参开始
$sql = "select * from  `#@__contact` where 1";
$dsql->SetQuery($sql);
$dsql->Execute();

$contact  = array();
while($row = $dsql->GetArray()){
$contact[] = $row;
}
// 联系我们传参结束


// 获得总的搜索院校的数组
$sql = "SELECT * FROM `#@__collegeinfo` WHERE  name LIKE '%$keyword%' AND $search $order";
$dsql->SetQuery($sql);
$dsql->Execute();
$college_search = array();
while($row = $dsql->GetArray()){
    $college_search[] = $row;
}



// 分页模板
$dlist = new DataListCP_Fore();
$dlist->SetParameter('keyword', $keyword);
$dlist->SetParameter('search_area', $search_area);
$dlist->SetParameter('search_feerange', $search_feerange);
$dlist->SetParameter('search_projecttype', $search_projecttype);
$dlist->SetParameter('search_scoretype', $search_scoretype);
$dlist->SetParameter('search_level', $search_level);
$dlist->SetParameter('orderby', $orderby);
$dlist->SetTemplet(DEDETEMPLATE.'/plus/college_search.htm');
$dlist->SetSource($sql);
$dlist->display();


// 对学费前台样式进行处理
function DealFee($lowet_fee,$highest_fee){
	$fee = '';
	if (!$lowet_fee) {
		$lowet_fee = 0;
	}
	$fee = $lowet_fee.'万';
	if ($highest_fee) {
		$fee .= '-'.$highest_fee.'万';
	}
	return $fee;
}

/**
 * 处理联动菜单值多个的情况
 * $egroup 为联动组
 * $evalue 为联动值，多个联动值的用","分隔
 */
function deal_multivalue($egroup,$evalue){
	$arr_value = explode(',', $evalue);
	$str_value = "";
	foreach ($arr_value as $key => $value) {
		$str_value .= GetEnumsValue($egroup,$value).','; 
	}
	$str_value = rtrim($str_value,',');
	return $str_value;
}





/**
 * 根据最近浏览院校的推荐函数，根据最多的学费范围，地区推荐
 * $history_college  最近浏览院校数组
 * return  推荐院校的数组 
 * by HehongChen
 * 2014.10.30
 */
function CollegeRecommend($history_ids){
	global $dsql;
	$history_ids_str = join(',',$history_ids);
	// 获取院校中最多的学费范围和地区
	$sql_max_feerange = "SELECT feeRange FROM `#@__collegeinfo` WHERE collegeId IN ($history_ids_str) group by feeRange order by count(feeRange) desc limit 1";
	$dsql->SetQuery($sql_max_feerange);
	$dsql->Execute();
	$max_feerange_arr = $dsql->GetArray();
	$max_feerange = $max_feerange_arr['feeRange'];

	$sql_max_area = "SELECT area FROM `#@__collegeinfo` WHERE collegeId IN ($history_ids_str) group by area order by count(area) desc limit 1";
	$dsql->SetQuery($sql_max_area);
	$dsql->Execute();
	$max_area_arr = $dsql->GetArray();
	$max_area = $max_area_arr['area'];

	// // 构造查询的sql语句
	$sql = "SELECT * FROM `#@__collegeinfo` WHERE  feeRange=$max_feerange AND area=$max_area AND collegeId NOT IN ($history_ids_str)";
	$dsql->SetQuery($sql);
	$dsql->Execute();
	$recommend_college = array();
	while($row = $dsql->GetArray()){
    	$recommend_college[] = $row;
	}
	
	return $recommend_college;
}





?>